﻿using System.Collections.Generic;

namespace Borg.Framework
{
    internal class CloseCommand : ICommand
    {
        private static string Close(string[] command)
        {
            string arg;

            if (command.Length < 3)
                return "Too few arguments.";

            var repoElements = RuntimeCommands.Find(command, 1, out arg);

            if (repoElements.Length == 0)
                return arg;

            foreach (SlotInfo info in repoElements)
                info.Close();

            return string.Empty;
        }

        public IEnumerable<string> GetArguments(string[] command, int pos)
        {
            switch (pos)
            {
                case 0:
                    return new[] { "SlotInfo" };

                case 1:
                    var args = new string[Runtime.Repository.SlotInfos.Count];

                    for (int i = 0; i < args.Length; i++)
                        args[i] = Runtime.Repository.SlotInfos[i].Name;

                    return args;
            }

            return null;
        }

        public CommandHandler Handler
        {
            get { return Close; }
        }

        public string Help
        {
            get { return "  Help for command \"close\""; }
        }

        public string Name
        {
            get { return "close"; }
        }
    }
}

